package com.hejjon.controller;

import com.hejjon.bean.ResponseResult;
import com.hejjon.dto.UserDto;
import com.hejjon.entity.XUser;
import com.hejjon.service.IXUserService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.List;

/**
 * Created by CaoShi on 2020/5/21 22:00
 */
@RestController
@RequestMapping("/user")
public class XUserController {

    @Autowired
    private IXUserService ixUserService;

    @RequestMapping("/list")
    ResponseResult listAllUser() throws ParseException {
        List<XUser> xUserList = ixUserService.queryAllUser();
        List<UserDto> userDtoList = new ArrayList<>();
        DateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        for (XUser xUser : xUserList) {
            UserDto userDto = new UserDto();
//            userDto.setId(xUser.getId());
//            userDto.setUsername(xUser.getUsername());
//            userDto.setRealname(xUser.getRealname());
//            userDto.setAddress(xUser.getAddress());
//            userDto.setBirthdayStr(format.format(xUser.getBirthday()));
//            userDto.setBirthday(format.parse(userDto.getBirthdayStr()));
//            userDto.setAge(xUser.getAge());
//            userDtoList.add(userDto);

            BeanUtils.copyProperties(xUser, userDto);
            userDtoList.add(userDto);
        }

        return new ResponseResult(0, "成功", "success", userDtoList);
    }



}
